<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" 
	import="java.util.List,com.ncr.teradata.bireport.CommonFunc,com.telecom.cms.dao.*,com.telecom.cms.dto.*" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<%
	String act = request.getParameter("act");
	int templateId = 0;
	String paramName = request.getParameter("paramName");
	List paramList = (List)session.getAttribute("sqlParamList");
	for (int i = 0; i < paramList.size(); i++){
		IdaTemplateAtomSql atom = (IdaTemplateAtomSql)paramList.get(i);
		if (atom.getParamName().equals(paramName)){
			if (act != null && act.equals("saveParam")){
				atom.setParamNameCn(CommonFunc.iso88591_utf8(request.getParameter("paramNameCn")));
				atom.setIsMatchAtom(request.getParameter("isMatchAtom") != null ? "10" : "20");
				if (atom.getIsMatchAtom().equals("10")){
					String atomId = request.getParameter("bizAtomId");
					if (atomId != null && !atomId.equals("")){
						List atomList = new IdaDAO().findAllAtom();
						for (int j = 0; j < atomList.size(); j++){
							SEG_BIZ_ATOM_DEFDTO tempAtom = (SEG_BIZ_ATOM_DEFDTO)atomList.get(j);
							if (tempAtom.getBIZ_ATOM_ID() == Integer.parseInt(atomId)){
								atom.setBizAtomId(tempAtom.getBIZ_ATOM_ID());
								atom.setBizAtomName(tempAtom.getBIZ_ATOM_NAME());
								break;
							}
						}
					}
				}
				else{
					atom.setBizAtomId(0);
					atom.setBizAtomName("");
				}
				atom.setDmnTableName(request.getParameter("dmnTableName"));
				atom.setDmnColumnName1(request.getParameter("dmnColumnName1"));
				atom.setDmnColumnName2(request.getParameter("dmnColumnName2"));
				atom.setValueTypeId(request.getParameter("valueTypeId"));
				atom.setShowTypeId(request.getParameter("showTypeId"));
				atom.setDefaultValue(request.getParameter("defaultValue"));
				atom.setDefaultValueName(request.getParameter("defaultValue"));
				atom.setIsNotEmpty(request.getParameter("isNotEmpty") != null ? "10" : "20");
				atom.setIsFiltOnly(request.getParameter("isFiltOnly") != null ? "10" : "20");
				atom.setIsLikeMatch(request.getParameter("isLikeMatch") != null ? "10" : "20");
				atom.setDisplayId(Integer.parseInt(request.getParameter("displayId")));
			}
			else
				request.setAttribute("sqlParam", atom);
			templateId = atom.getTemplateId();
			break;
		}
	}
	if (act != null && act.equals("saveParam"))
		out.println("<script>document.location.href = '../idaTemplate.do?method=sqlTemplate&reloadParam=false&templateId=" + templateId + "';</script>");
%>
<html>
<head>
	<title>JSP for SysTeamForm form</title>
	<LINK href="css/default.css" rel=stylesheet>
	<LINK href="css/button.css" rel=stylesheet>
<script type="text/javascript">
	function save(){
		form1.submit();
	}
	
	function cancel(){
		document.location.href = 'idaTemplate.do?method=sqlTemplate&reloadParam=false&templateId=${sqlParam.templateId}';
	}

	function Atomoption (text,value){
		this.text=text;
		this.value=value;
	}
	
	var atoms=new Array();
	
	function ChangeGroup()
	{ 
		var i,iGroupIndex;
		iGroupIndex=document.all.groups.selectedIndex;
		iAtomCount=0; 
		while (atoms[iGroupIndex][iAtomCount]!=null) 
		 iAtomCount++;
		 //计算选定组下的原子个数 
		document.all.bizAtomId.length=0;//清空选项数 
		for(i=0;i<=iAtomCount-1;i++){//改变下拉菜单的内容 
			document.all.bizAtomId.add(new Option(atoms[iGroupIndex][i].text,atoms[iGroupIndex][i].value));
		}
		document.all.bizAtomId.focus();
	}
</script>
</head>
<body>
<form name="form1" action="ida/configSqlParam.jsp">
<table width="770" cellspacing="0" cellpadding="0" border="0" align="center">
<tbody>
	<tr>
		<td width="3" height="31">
			<img height="31" src="images/table_01.gif" width="3" />
		</td>
		<td background="images/table_02.gif" height="31">
			<table cellspacing="0" cellpadding="0" width="146" align="left" border="0">
				<tbody>
					<tr>
						<td width="51" background="images/title_1_bg.gif">
							<img height="31" src="images/title_1.gif" width="51" />
						</td>
						<td width="95" background="images/title_1_bg.gif">
							<span class="color_b_666">参数配置</span>
						</td>
					</tr>
				</tbody>
			</table>
		</td>
		<td width="3">
			<img height="31" src="images/table_03.gif" width="3" />
		</td>
	</tr>
	<tr>
		<td background="images/table_04.gif">
			<img height="5" src="images/table_04.gif" width="3">
		</td>
		<td style="PADDING-TOP: 3px" valign="top">
		<logic:present name="sqlParam" scope="request">
			<table width='70%' border='0' cellspacing='1' cellpadding='2' align="center">
				<th colspan="2" height="30">SQL参数配置信息</th>
				<tr height="30">
					<td width="100" align="center">参数名称：</td>
					<td align="left">
						${sqlParam.paramName}${sqlParam.dmnColumnName1}
					</td>
				</tr>
				<tr height="30">
					<td width="100" align="center">中文名称：</td>
					<td align="left">
						<input type="text" name="paramNameCn" value="${sqlParam.paramNameCn}" size="40" />
					</td>
				</tr>
				<tr height="30">
					<td width="100" align="center">关联业务原子：</td>
					<td align="left">
						<input type="checkbox" name="isMatchAtom" value="10" <logic:equal name="sqlParam" property="isMatchAtom" value="10">checked</logic:equal>>&nbsp;
						<select name="groups" id="groups" onchange="ChangeGroup()">
						<%
							IdaDAO idadao = new IdaDAO();
							List grouplist = idadao.findAllAtomGroup();
							int idx = 0;
							for (int i = 0; i < grouplist.size(); i++) {
								SEG_BIZ_GROUP_DEFDTO groupdto = (SEG_BIZ_GROUP_DEFDTO) grouplist.get(i);
						%>
							<option value=<%=groupdto.getATOM_GROUP_ID()%>><%=groupdto.getATOM_GROUP_NAME()%></option>
							<script type="text/javascript">atoms[<%=idx%>]=new Array(); </script>
							<%
								List groupAtoms = idadao.findGroupAtoms(groupdto.getATOM_GROUP_ID());
								if (groupAtoms != null && groupAtoms.size() > 0)
									for (int j = 0; j < groupAtoms.size(); j++) {
										SEG_BIZ_ATOM_DEFDTO showdto = (SEG_BIZ_ATOM_DEFDTO)groupAtoms.get(j);
							%>
							<script type="text/javascript">atoms[<%=idx%>][<%=j%>]=new Atomoption('<%=showdto.getBIZ_ATOM_NAME()%>',<%=showdto.getBIZ_ATOM_ID()%>) </script>
						<%
								}
								idx++;
							}
						%>
						</select>&nbsp;
						<select name="bizAtomId" id="bizAtomId" onchange="">
						</select>
					</td>
				</tr>
				<tr height="30">
					<td width="100" align="center">维表：</td>
					<td align="left">
						<input type="text" name="dmnTableName" value="${sqlParam.dmnTableName}" size="40" />
					</td>
				</tr>
				<tr height="30">
					<td width="100" align="center">列名称：</td>
					<td align="left">
						<input type="text" name="dmnColumnName1" value="${sqlParam.dmnColumnName1}" size="40" />
					</td>
				</tr>
				<tr height="30">
					<td width="100" align="center">显示列名称：</td>
					<td align="left">
						<input type="text" name="dmnColumnName2" value="${sqlParam.dmnColumnName2}" size="40" />
					</td>
				</tr>
				<tr height="30">
					<td width="100" align="center">值类型：</td>
					<td align="left">
						<select name="valueTypeId" id="valueTypeId">
							<option value="CHAR" <logic:equal name="sqlParam" property="valueTypeId" value="CHAR">selected</logic:equal>>CHAR</option>
							<option value="VARCHAR" <logic:equal name="sqlParam" property="valueTypeId" value="VARCHAR">selected</logic:equal>>VARCHAR</option>
							<option value="INTEGER" <logic:equal name="sqlParam" property="valueTypeId" value="INTEGER">selected</logic:equal>>INTEGER</option>
							<option value="DECIMAL" <logic:equal name="sqlParam" property="valueTypeId" value="DECIMAL">selected</logic:equal>>DECIMAL</option>
						</select>
					</td>
				</tr>
				<tr height="30">
					<td width="100" align="center">展现形式：</td>
					<td align="left">
						<select name="showTypeId" id="showTypeId">
							<option value="10" <logic:equal name="sqlParam" property="showTypeId" value="10">selected</logic:equal>>输入框</option>
							<option value="11" <logic:equal name="sqlParam" property="showTypeId" value="11">selected</logic:equal>>下拉选择框</option>
							<option value="12" <logic:equal name="sqlParam" property="showTypeId" value="12">selected</logic:equal>>单选框</option>
							<option value="13" <logic:equal name="sqlParam" property="showTypeId" value="13">selected</logic:equal>>复选框</option>
							<option value="14" <logic:equal name="sqlParam" property="showTypeId" value="14">selected</logic:equal>>区间输入</option>
							<option value="15" <logic:equal name="sqlParam" property="showTypeId" value="15">selected</logic:equal>>树形结构展示</option>
							<option value="16" <logic:equal name="sqlParam" property="showTypeId" value="16">selected</logic:equal>>日期选择框</option>
							<option value="17" <logic:equal name="sqlParam" property="showTypeId" value="17">selected</logic:equal>>下拉式多选框</option>
						</select>
					</td>
				</tr>
				<tr height="30">
					<td width="100" align="center">默认值：</td>
					<td align="left">
						<input type="text" name="defaultValue" value="${sqlParam.defaultValue}" size="40" />
					</td>
				</tr>
				<tr height="30">
					<td width="100" align="center">其他选项：</td>
					<td align="left">
						<input type="checkbox" name="isNotEmpty" value="10" <logic:equal name="sqlParam" property="isNotEmpty" value="10">checked</logic:equal>>必填&nbsp;&nbsp;
						<input type="checkbox" name="isFiltOnly" value="10" <logic:equal name="sqlParam" property="isFiltOnly" value="10">checked</logic:equal>>过滤&nbsp;&nbsp;
						<input type="checkbox" name="isLikeMatch" value="10" <logic:equal name="sqlParam" property="isLikeMatch" value="10">checked</logic:equal>>模糊匹配&nbsp;&nbsp;
					</td>
				</tr>
				<tr height="30">
					<td width="100" align="center">显示顺序：</td>
					<td align="left">
						<input type="text" name="displayId" value="${sqlParam.displayId}" size="2" />
					</td>
				</tr>
				<tr>
					<td align="center" colspan="2">
						<div align="center" id="commit"><br/>
							<img src='images/button_true.gif' width="63" height="21" onclick="save()" />
							&nbsp;&nbsp;
							<img src='images/button_cancel.gif' width="63" height="21" onclick="cancel()" />
						</div>
					</td>
				</tr>
			</table>
		</logic:present>
		</td>
		<td background="images/table_05.gif">
			<img height="5" src="images/table_05.gif" width="3">
		</td>
	</tr>
	<tr height="3">
		<td height="3">
			<img height="12" src="images/table_06.gif" width="3">
		</td>
		<td height="3">
			<img height="3" src="images/table_07.gif" width="764">
		</td>
		<td height="3">
			<img height="12" src="images/table_08.gif" width="3">
		</td>
	</tr>
</tbody>
</table>
<br />
<input type="hidden" name="act" value="saveParam">
<input type="hidden" name="paramName" value="<%= paramName %>">
</form>
<script type="text/javascript">
	document.all.groups.selectedIndex=0;
	document.all.bizAtomId.add(new Option('${sqlParam.bizAtomName}','${sqlParam.bizAtomId}'));
</script>
</body>
</html>